package main

import (
	"github.com/gin-gonic/gin"
	"github.com/webview/webview"
	"log"
	"net"
)

func main() {
	ln, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		log.Fatal(err)
	}
	addr := ln.Addr().String()
	ln.Close()
	go func() {
		// Set up your http server here
		r := gin.Default()
		r.GET("/", func(c *gin.Context) {
			c.String(200, "index")
		})
		r.GET("/ping", func(c *gin.Context) {
			c.JSON(200, gin.H{
				"message": "word",
			})
		})
		log.Println("addr: " + addr)
		r.Run(addr)

		//log.Fatal(http.Serve(ln, nil))
	}()
	log.Println("main")

	debug := true
	w := webview.New(debug)
	defer w.Destroy()
	w.SetTitle("Minimal webview example")
	w.SetSize(800, 600, webview.HintNone)
	w.Navigate("https://www.baidu.com")
	w.Run()
}
